package com.coder520.activitylaunchmode;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
 * Created by huang on 2017/7/2.
 */

public abstract class BaseActivity extends Activity {
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextView = (TextView) findViewById(R.id.text_app_name);
        String value = String.format(getString(R.string.showing_text_format),
                getActivityName(), Integer.toHexString(hashCode()), getTaskId()+"");
        mTextView.setText(value);
        findViewById(R.id.btn_switch_next).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(BaseActivity.this, getNextActivity());
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                    }
                }
        );
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d(getActivityName(), getActivityName() +  " onNewIntent called");
    }

    protected abstract String getActivityName();
    protected abstract Class getNextActivity();
}
